import React from 'react';
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
import WayList from './wayList';
import WayDetail from './wayDetail';
import StationDetail from './stationDetail';

const routers = [
  { path: '/', exact: true, component: WayList },
  { path: '/waydetail/:line', component: WayDetail },
  { path: '/station-detail/:line', component: StationDetail },

];

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <Switch>
          {
            routers.map((item, index) => (
              <Route
                key={index}
                path={item.path}
                exact={item.exact}
                component={(props) => {
                  window.g_history = props.history;
                  return (<item.component {...props} />);
                }}
              />
            ))
          }
          <Route component={() => '404页面'} />
        </Switch>
      </Router>
    );
  }
}
